﻿Imports MeoTom.Core.DAL

Namespace BLL
    Public Class Users
        Public lg As New Logging()
        Public u As UserProvider
        Private _ID As Integer
        Private _UserName As String
        Private _Password As String
        Private _Email As String
        Private _CreateDate As DateTime

        Public Property ID() As Integer
            Get
                Return _ID
            End Get
            Set(ByVal value As Integer)
                _ID = value
            End Set
        End Property

        Public Property UserName() As String
            Get
                Return _UserName
            End Get
            Set(ByVal value As String)
                _UserName = value
            End Set
        End Property

        Public Property Password() As String
            Get
                Return _Password
            End Get
            Set(ByVal value As String)
                _Password = value
            End Set
        End Property

        Public Property Email() As String
            Get
                Return _Email
            End Get
            Set(ByVal value As String)
                _Email = value
            End Set
        End Property

        Public Property CreateDate() As DateTime
            Get
                Return _CreateDate
            End Get
            Set(ByVal value As DateTime)
                _CreateDate = value
            End Set
        End Property

        Public Sub New()
            u = New UserProvider()
        End Sub

        Public Sub ResetPassword()
            Try
                u.ResetPassword(Me)
            Catch ex As Exception
                lg.WriteLog(ex.Message, "Reset Password Error !!")
            End Try
        End Sub

        Public Function Login() As Boolean
            Dim b As Boolean = False
            Try
                Dim reader As SqlClient.SqlDataReader = u.Login(Me)
                If reader.Read() Then
                    Me.UserName = reader("UserName").ToString()
                    Me.ID = Integer.Parse(reader("ID").ToString())
                    Me.Email = reader("Email").ToString()
                    b = True
                Else
                    b = False
                End If
                reader.Close()
            Catch ex As Exception
                lg.WriteLog(ex.Message, "User Login Fail !!")
            End Try
            Return b
        End Function
    End Class
End Namespace